@/*
    表单中SelectTree框标签中各个参数的说明:
    id : input框id
    name : input框名称
    value : value
    textValue :textValue
    url : 树地址
    isMulti : 是否多选-默认单选
    selectRoot : 是否可选root
    selectSelf : 是否可选自己
    underline：
    readonly
@*/
@if(isEmpty(width)){
@	width="100%";
@}
@if(isEmpty(selectRoot)){
@	selectRoot=false;
@}
@if(isEmpty(selectSelf)){
@	selectSelf=false;
@}
@if(isEmpty(readonly)){
@	readonly=false;
@}else{
@	readonly=readonly=="true"?true:false;
@}
@if(isEmpty(isMulti)){
@	isMulti=false;
@}else{
@	isMulti=isMulti=="false"?false:true;
@}
@if(isEmpty(width)){
@	width="100%";
@}
<div class="form-group">
    @if(!isEmpty(name)){
    <label class="lab">${name}</label>
    @}
    <div class="ele ${isEmpty(name)?'ele-fit':''}">
        <input id="${id}" name="${id}" value="${value!}" type="hidden"/>
	    @if(isMulti){
	        <textarea class="textbox" id="${id}_text" name="${id}_text" style="float:left;width:${width!};margin: 0px">${textValue!}</textarea>
	    @}else{
	    	<input class="textbox" id="${id}_text" name="${id}_text" value="${textValue!}" type="text" style="float:left;${width!};margin: 0px"/>
	    @}
@if(!readonly){
    	<i class="clearicon" id="${id}_clear"></i>
@}
		@if(isNotEmpty(tips)){
	        <span class="help-block m-b-none">${tips!}</span>
		@}
    </div>
</div>
@if(!readonly){
	<script type="text/javascript">
	    $("#${id}_text").click(function(){
	    	var ids = $("#${id}").val();
	    	var opt = {
	                type: 2,
	                title: '选择${name!}',
	                area: ['300px', '450px'], //宽高
	                fix: false, //不固定
	                maxmin: true,
	                content: '/static/common/_selecttree.html',
	                success: function(layero, index){
	                    var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
	                    iframeWin.initTree("${backendPath}${url!}",${isMulti!false},ids);
	                }
	            }
			opt["btn"]=[];
	    	opt.btn.push('<i class="fa fa-check"></i> 确定');
	    	opt['btn'+opt.btn.length] = function(index, layero){
	            var win = window[layero.find('iframe')[0]['name']];
				win.$('#keyword').val('').change();
				var codes = [], names = [], nodes;
				if (${isMulti!false}){
					nodes = win.tree.getCheckedNodes(true);
				}else{
					nodes = win.tree.getSelectedNodes();
				}
				for(var i=0; i<nodes.length; i++) {
					if (nodes[i].level == 0 && nodes[i].isParent && (!${selectRoot})){
						Sys.info("不能选择根节点（"+nodes[i].name+"）请重新选择。");
						return false;
					}
					if($("#id")&&$("#id").val()==nodes[i].id&&nodes[i].id!=0 && (!${selectSelf})){
						Sys.error("不要选自己啦！")
						return false;
					}
					var code = (nodes[i].value || nodes[i].id)+"", name = nodes[i].name;
					codes.push(code.replace(/^u_/g,''));
					names.push(name.replace(/\([0-9]*\)/g,''));
				}
				$("#${id}").val(codes.join(',')).change();
				$("#${id}_text").val(names.join(',')).change();
	            layer.close(index);
	    	};
	
	    	opt.btn.push('<i class="fa fa-eraser"></i> 清除');
	    	opt['btn'+opt.btn.length] = function(index, layero){
	    		$("#${id}").val('').change();
	    		$("#${id}_text").val('').change();
	    	};
	
	    	opt.btn.push('<i class="fa fa-close"></i> 关闭');
	    	opt['btn'+opt.btn.length] = function(index, layero){
	            var index = layer.getFrameIndex(layero.find('iframe')[0]['name']); //获取窗口索引
	            layer.close(index);
	    	};
	
	        layer.open(opt);
	    });
		$("#${id}_clear").click(function(){
	        $('#${id}_text').val('').change();
	        $('#${id}').val('').change();
	    })
	</script>
@}
@if(isNotEmpty(underline) && underline == 'true'){
    <div class="hr-line-dashed"></div>
@}
